//
//  CHStyle.swift
//  yzb
//
//  Created by cyptt on 2021/10/22.
//

import Foundation
import UIKit
class CHTabBarStyle: NSObject {
    
    class func CHRGBColor(red:CGFloat,green:CGFloat,blue:CGFloat)->UIColor{
        return UIColor.init(red: red/255.0, green: green/255.0, blue: blue/255.0, alpha: 1)
    }
    //导航栏的背景颜色
    class func navigarionBarColor() -> UIColor {
        return self.CHRGBColor(red: 29.0, green: 171.0, blue: 177.0)
    }
    
    //设置tabbarcolor #04A0F6
    class func tabbarColor() -> UIColor{
        return self.CHRGBColor(red: 4, green: 160, blue: 246)
    }
    
    
    class func getJsonWithName(name:String) -> NSArray{
        //沙盒加载json
        let docStr = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
        let jsonPath = (docStr as NSString).appendingPathComponent("\(name).json");
        var data = NSData(contentsOfFile: jsonPath)
        
        //如果沙盒中没有main.json，从本地加载
        
        if data == nil {
            
            //获取值为nil的问题：项目-->Build Phases --> copy Bundle Resource 中没有加入此文件
            let filePath = Bundle.main.path(forResource: name, ofType: "json")
            data = NSData(contentsOfFile: filePath!);
        }
        guard let array = try?JSONSerialization.jsonObject(with: data! as Data, options: []) as?[[String:AnyObject]] else{
            return NSArray()
        }
        return array as NSArray
    
    }
}
